package com.sumainfor.pc.gmio.service.impl;

import com.alibaba.druid.sql.visitor.functions.If;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.CompuUtils;
import com.sumainfor.pc.gmio.dao.ServiceSecretaryDeskMapper;
import com.sumainfor.pc.gmio.feign.Zfeign.ZwxTenantFeign;
import com.sumainfor.pc.gmio.service.ServiceSecretaryDeskService;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务秘书工作台
 * <p>
 *
 * @author: zhoucong
 * @create: 2019-06-05 16:59
 **/
@Service
public class ServiceSecretaryDeskServiceImpl implements ServiceSecretaryDeskService {

   @Autowired
    ServiceSecretaryDeskMapper serviceSecretaryDeskMapper;


   @Autowired
    ZwxTenantFeign zwxTenantFeign;

    /**
    * <p>
    * 重要状态提醒
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @Override
    public JsonResult getImport(){
        JsonResult result = new JsonResult();
        return result.put(serviceSecretaryDeskMapper.getImport());
    }

    /**
    * <p>
    * 日账单核对
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @Override
    public JsonResult DailyReconciliation() {
        JsonResult result = new JsonResult();
        Map<String,Object> map = new HashMap<>();
        double NowAudit =0;
        double ToAudit =0;
        List<Map<String, Object>> getNowAuditList = serviceSecretaryDeskMapper.getNowAudit();
        if(getNowAuditList.size()<=0){
          map.put("NowAudit",0);
        }else {
            for (Map<String, Object> getNowAuditMap : getNowAuditList) {
                NowAudit = CompuUtils.add(NowAudit, MapUtils.getDouble(getNowAuditMap, "PayMoney"));
            }
            map.put("NowAudit",NowAudit);
        }
        List<Map<String, Object>> getToAuditList = serviceSecretaryDeskMapper.getToAudit();
        if (getToAuditList.size()<=0){
            map.put("ToAudit",0);
        }else {
            for (Map<String, Object> getToAudit : getToAuditList) {
                ToAudit = CompuUtils.add(ToAudit, MapUtils.getDouble(getToAudit, "BiMoney"));
            }
            map.put("ToAudit",ToAudit);
        }

        return result.put(map);
    }

    /**
    * <p>
    * 根据传入手机号查询租客全部账单
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @Override
    public JsonResult getAllTheBills(Map<String,Object> params){
        JsonResult result = new JsonResult();
        double sum1 = 0;
        double sum2 = 0;
        double sum3 = 0;
        double sum4 = 0;
        double sum5 = 0;
        double sum6 = 0;
        double sum7 = 0;
        Map<String, Object> mapOne = new HashMap<>();
        JsonResult zwxTenantResult = zwxTenantFeign.getTenantTenPhone(params);
        Map<String,Object> zwxTenantMap = (Map<String, Object>) zwxTenantResult.get("result");
        if (!MapUtils.isEmpty(zwxTenantMap)) {
            List<Map<String, Object>> AllBillList = serviceSecretaryDeskMapper.getAllTheBills(zwxTenantMap);
            if (AllBillList.size() > 0) {
                for (Map<String, Object> AllBillMap : AllBillList) {
                    Double BiMoney = MapUtils.getDouble(AllBillMap, "BiMoney");
                    if (MapUtils.getInteger(AllBillMap, "BiType") == 1) {
                        sum1 = CompuUtils.add(sum1, BiMoney);
                    }
                    if (MapUtils.getInteger(AllBillMap, "BiType") == 2) {
                        sum2 = CompuUtils.add(sum2, BiMoney);
                    }
                    if (MapUtils.getInteger(AllBillMap, "BiType") == 3) {
                        sum3 = CompuUtils.add(sum3, BiMoney);
                    }
                    if (MapUtils.getInteger(AllBillMap, "BiType") == 4) {
                        sum4 = CompuUtils.add(sum4, BiMoney);
                    }
                    if (MapUtils.getInteger(AllBillMap, "BiType") == 5) {
                        sum5 = CompuUtils.add(sum5, BiMoney);
                    }
                    if (MapUtils.getInteger(AllBillMap, "BiType") == 6) {
                        sum6 = CompuUtils.add(sum6, BiMoney);
                    }
                    if (MapUtils.getInteger(AllBillMap, "BiType") == 7) {
                        sum7 = CompuUtils.add(sum7, BiMoney);
                    }
                }
            }
            double sum8 = CompuUtils.add(CompuUtils.add(CompuUtils.add(sum3, sum4), CompuUtils.add(sum1, sum2)), CompuUtils.add(CompuUtils.add(sum5, sum6), sum7));
            mapOne.put("sum1", sum1);
            mapOne.put("sum2", sum2);
            mapOne.put("sum3", sum3);
            mapOne.put("sum4", sum4);
            mapOne.put("sum5", sum5);
            mapOne.put("sum6", sum6);
            mapOne.put("sum7", sum7);
            mapOne.put("sum8", sum8);
        }else{
            mapOne.put("sum1", 0);
            mapOne.put("sum2", 0);
            mapOne.put("sum3", 0);
            mapOne.put("sum4", 0);
            mapOne.put("sum5", 0);
            mapOne.put("sum6", 0);
            mapOne.put("sum7", 0);
            mapOne.put("sum8", 0);
        }
//
//        if (!MapUtils.isEmpty(zwxTenantMap)) {
//            List<Map<String, Object>> AllBillList = serviceSecretaryDeskMapper.getAllTheBills(zwxTenantMap);
//            if (AllBillList.size() > 0) {
//                for (Map<String, Object> AllBillMap : AllBillList) {
//                    Double BiMoney = MapUtils.getDouble(AllBillMap, "BiMoney");
//                    if (MapUtils.getInteger(AllBillMap, "BiType") == 1) {
//                        sum1 = CompuUtils.add(sum1, BiMoney);
//                    }
//                    if (MapUtils.getInteger(AllBillMap, "BiType") == 2) {
//                        sum2 = CompuUtils.add(sum2, BiMoney);
//                    }
//                    if (MapUtils.getInteger(AllBillMap, "BiType") == 3) {
//                        sum3 = CompuUtils.add(sum3, BiMoney);
//                    }
//                    if (MapUtils.getInteger(AllBillMap, "BiType") == 4) {
//                        sum4 = CompuUtils.add(sum4, BiMoney);
//                    }
//                    if (MapUtils.getInteger(AllBillMap, "BiType") == 5) {
//                        sum5 = CompuUtils.add(sum5, BiMoney);
//                    }
//                    if (MapUtils.getInteger(AllBillMap, "BiType") == 6) {
//                        sum6 = CompuUtils.add(sum6, BiMoney);
//                    }
//                    if (MapUtils.getInteger(AllBillMap, "BiType") == 7) {
//                        sum7 = CompuUtils.add(sum7, BiMoney);
//                    }
//                }
//            }
//            double sum8 = CompuUtils.add(CompuUtils.add(CompuUtils.add(sum3, sum4), CompuUtils.add(sum1, sum2)), CompuUtils.add(CompuUtils.add(sum5, sum6), sum7));
//            mapOne.put("sum1", sum1);
//            mapOne.put("sum2", sum2);
//            mapOne.put("sum3", sum3);
//            mapOne.put("sum4", sum4);
//            mapOne.put("sum5", sum5);
//            mapOne.put("sum6", sum6);
//            mapOne.put("sum7", sum7);
//            mapOne.put("sum8", sum8);
//        }else{
//            mapOne.put("sum1", 0);
//            mapOne.put("sum2", 0);
//            mapOne.put("sum3", 0);
//            mapOne.put("sum4", 0);
//            mapOne.put("sum5", 0);
//            mapOne.put("sum6", 0);
//            mapOne.put("sum7", 0);
//            mapOne.put("sum8", 0);
//        }
        return result.put(mapOne);
    }
}
